#ifndef API_NEWCODE_H
#define API_NEWCODE_H

#ifdef WIN32
#   ifdef NC_EXPORTS
#       define NC_API __declspec(dllexport)
#   else
#       define NC_API __declspec(dllimport)
#   endif
#else
#   define NC_API
#endif

#ifdef __cplusplus
extern "C" {
#endif

#define ncchar char

typedef enum
{
    MODE_2_LEVELS,
    MODE_4_LEVELS,
    MODE_8_LEVELS,
    MODE_3_LEVELS
} NC_Mode;

typedef enum
{
    ERROR_NO_ERRORS,
    ERROR_NOT_FOUNND,
    ERROR_BAD_FORMAT,
    ERROR_UNNAMED
} NC_ErrorCode;

/**
 * Result of decode. "text" is UTF-8 string (will be NULL if code is binary).
 * "points" is corners of code in image.
 */
typedef struct
{
    ncchar* text;
    unsigned char* rawBytes;
    float points[8];

} NC_DecodeResult;

typedef struct
{
    int code;
    const char* what;
} NC_Error;

/**
 * Encodes string.
 * Free result after usage.
 * Returned matrix is always square of "size" pixels.
 */
NC_API unsigned char**
nc_encode(ncchar* data, NC_Mode mode, int *size, NC_Error* error);

/**
 * Encodes rawBytes.
 * Free result after usage.
 * Returned matrix is always square of "size" pixels.
 */
NC_API unsigned char**
nc_encode_raw(unsigned char* data, int len, NC_Mode mode, int *size,
    NC_Error* error);

/**
 * Decodes greyscale image. Call "nc_release_result" afrter returned object is
 * not needed already.
 */
NC_API NC_DecodeResult*
nc_decode(unsigned char **image, int sizeX, int sizeY, NC_Error* error);

NC_API void nc_release_result(NC_DecodeResult* result);

#ifdef __cplusplus
}
#endif
#endif // API_H
